package com.hosever.action;

import java.util.Date;


public class Test {
	public static void main(String[] args) {
		User u1 = new User(new Date(),"leung");
		
//		User u2 = u1;
//		
//		u2.setAge(13);
//		
//		System.out.println(u1.getAge());
//		System.out.println(u1.hashCode());
//		System.out.println(u2.hashCode());
		
		User u2  = u1.clone();
		u2.setName("ho");
		System.out.println(u1.getName());
		System.out.println(u2.getName());
		System.out.println(u1.getName().hashCode());
		System.out.println(u2.getName().hashCode());//与u1的内存地址一样，说明对象是浅拷贝
	}
}

class User implements Cloneable{
	private Date birthDay;
	private String name;

	public User() {
	}
	public User(Date birthDay, String name) {
		super();
		this.birthDay = birthDay;
		this.name = name;
	}


	public User clone() {
		try {
			return (User) super.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return null;
	}
	

	public Date getBirthDay() {
		return birthDay;
	}

	public void setBirthDay(Date birthDay) {
		this.birthDay = birthDay;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	
	
}




